<?php

class Uri {
    
    public function make ($string, array $param = array()) {
        
        foreach ($param as $key => $value) {
            if (! empty($value)) {
                $paramString .= urlencode($key) . '/' . urlencode($value) . '/';
            }
        }
        $app = APP_NAME === Config::get('application', 'default') ? '' : APP_NAME . '/';
        $string = $string ? $string . '/' : '';
        return '/' . $app . $string . $paramString;
    }
    
    public function parse ($uri) {
        
        $array = explode('/', rtrim($uri, '/'));
        
        $controller = array_shift($array);
        $action = array_shift($array);
        
        $controller = ucfirst(strtolower($controller));
        $action = strtolower($action);
        
        $params = array();
        
        while (! empty($array)) {
            $key = urldecode(array_shift($array));
            $value = urldecode(array_shift($array));
            $params[$key] = $value;
        }
        
        return array(
            'controller' => $controller , 
            'action' => $action , 
            'params' => $params);
    }
}
?>